﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LibrarySystem
{
    public partial class TotalSales : Form
    {
        AppManager LIB = new AppManager();
        public TotalSales()
        {
            InitializeComponent();
        }

        private void TotalSales_Load(object sender, EventArgs e)
        {
            label2.Hide();
            label3.Hide();
            label4.Hide();
            dateTimePicker1.Hide();
            dateTimePicker2.Hide();
            button7.Enabled = false;
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            label2.Hide();
            label3.Hide();
            label4.Show();
            dateTimePicker1.Show();
            dateTimePicker1.Text = DateTime.Now.ToShortDateString();
            dateTimePicker2.Hide();
            button7.Enabled = true;
            label5.Text = "";
            label36.Text = "";
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            label2.Show();
            label3.Show();
            label4.Hide();
            dateTimePicker1.Show();
            dateTimePicker1.Text = DateTime.Now.ToShortDateString();
            dateTimePicker2.Show();
            dateTimePicker2.Text = DateTime.Now.ToShortDateString();
            button7.Enabled = true;
            label5.Text = "";
            label36.Text = "";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            label5.Text = "";
            label36.Text = "";
            if (radioButton1.Checked == true)
            {
                LIB.FunSUM("SELECT SUM(الإجمالي_بعد_الخصم) FROM alssafa.dbo.Bill WHERE التاريخ = '" + dateTimePicker1.Text + "'", label6);
                if (label6.Text.Length > 0)
                {
                    label5.Text = label6.Text;
                }
                else
                    label5.Text = "0";

            }
            else if (radioButton2.Checked == true)
            {
                if (dateTimePicker2.Value > dateTimePicker1.Value || dateTimePicker2.Value.Equals(dateTimePicker1.Value))
                {
                    LIB.FunSUM("SELECT SUM(الإجمالي_بعد_الخصم) FROM alssafa.dbo.Bill WHERE التاريخ BETWEEN '" + dateTimePicker1.Text + "' AND '" + dateTimePicker2.Text + "'", label6);
                    if (label6.Text.Length > 0)
                    {
                        label5.Text = label6.Text;
                    }
                    else
                        label5.Text = "0";
                }
                else
                    label36.Text = "أدخل فترة صحيحة";

            }
        }
    }
}
